LINQ - RSS Aggregator using LINQ to XML


LINQ, XML
RSS, LINQ to XML
Web, Data
en-US
7/8/2011

Introduction

This sample acts as a tiny web server that aggregates several RSS feeds.

Building the Sample

Press F5

Description

This sample acts as a small Web server that aggregates several RSS feeds. An Internet connection is required. On Windows Vista, you may have to run this program as Administrator.

*Note: In the sample code below there is a list of feeds.  If you run this sample and it returns a 404 error, browse to each URL individually and verify that each one still exists.

Sample Code

 

C#
Edit|Remove
    static XElement GetReplyBody() { 
        return new XElement("rss", 
            new XAttribute("version", "2.0"), 
            new XElement("channel", 
              new XElement("title", "C# Geeks"), 
              new XElement("link", feedUrl), 
              new XElement("description", "C# Team Members"), 
              new XElement("generator", "LinqToXml-based RSS aggregator"), 
              GetItems().ToArray() 
              )); 
 
    }
 

 

Visual Basic
Edit|Remove
Function GetReplyBody() As XElement 
        Dim feeds() As String = {"http://blogs.msdn.com/vbteam/rss.aspx?Tags=Amanda+Silver&AndTags=1", _ 
                                 "http://blogs.msdn.com/vbteam/rss.aspx?Tags=Beth+Massi&AndTags=1", _ 
                                 "http://blogs.msdn.com/vbteam/rss.aspx?Tags=Matt+Gertz&AndTags=1", _ 
                                 "http://blogs.msdn.com/vbteam/rss.aspx?Tags=LINQ_2F00_VB9&AndTags=1", _ 
                                 "http://blogs.msdn.com/vbteam/rss.aspx?Tags=VB6_5F00_Migration_2F00_Interop&AndTags=1", _ 
                                 "http://www.panopticoncentral.net/Rss.aspx", _ 
                                 "http://blogs.msdn.com/vsdata/rss.xml", _ 
                                 "http://blogs.msdn.com/vbteam/rss.aspx?Tags=IDE&AndTags=1"} 
 
        Return <rss version="2.0"> 
                   <channel> 
                       <title>VB Genius</title> 
                       <link>http://+:8086/VBfeeds/</link> 
                       <description>VB Team Members</description> 
                       <generator>XLinq-based RSS aggregator using VB Only Super Cool XML Literals Feature</generator> 
                       <%= From f In feeds Let feed = XDocument.Load(f) Select feeditem = feed.Root.Element("channel").Elements("item") From si In feeditem Select si %> 
                   </channel> 
               </rss> 
    End Function

Source Code Files

More Information

For more information on LINQ to XML: http://msdn.microsoft.com/en-us/library/bb387098.aspx